import { dateFormat } from "@/utils/date"

export const initForm = () => {
  return {
    roleIds: [],
    shipId: "",
    password: undefined,
    wpassword: undefined
  }
}

var validatePass2 = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请再次输入密码'));
  } else if (value !== this.ruleForm.pass) {
    callback(new Error('两次输入密码不一致!'));
  } else {
    callback();
  }
};

export const rules = {
  username: [
    { required: true, message: "必填", trigger: "blur" }
  ],
  usedeptIdrname: [
    { required: true, message: "必填", trigger: "change" }
  ],
  phone: [
    { required: true, message: "必填", trigger: "blur" }
  ],
  password: [
    { required: true, message: "必填", trigger: "blur" }
  ],
  roleIds: [
    { required: true, message: "必填", trigger: "change" }
  ],
  userType: [
    { required: true, message: "必填", trigger: "change" }
  ],
  shipId: [
    { required: true, message: "必填", trigger: "change" }
  ],
  nickname: [
    { required: true, message: "必填", trigger: "blur" }
  ],
  wpassword: [
    { validator: validatePass2, trigger: 'blur' }
  ]
}

export const initSearchForm = () => {
  return {
    current: 1,
    size: 10,
    userName: undefined,
    phonenumber: undefined,
    status: undefined,
    deptId: undefined
  }
}

export const statusOptions = [
  {
    label: "正常",
    value: 0
  }, {
    label: "锁定",
    value: 1
  }
]

export const getDeptName = (id, list) => {
  if (id === "-1" && !id) return ""
  let DeptName = ""
  let fn = (id, data) => {
    for (let item of data) {
      if (item.id === id) {
        DeptName = item.deptName
        return false
      }
      if (item.children && item.children.length > 0) {
        fn(id, item.children)
      }
    }
  }
  fn(id, list)
  return DeptName
}

export const initPermitForm = () => {
  return {
    current: 1,
    size: 10,
  }
}

export const options = {
  tip: false,
  stripe: true,
  simplePage: true,
  searchShow: true,
  searchMenuSpan: 6,
  border: true,
  index: true,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  menuWidth: 300,
  labelWidth: 170,
  searchLabelWidth: 100,
  dialogClickModal: false,
  column: [
    {
      label: "用户名称",
      prop: "username",
      search: true,
      display: true,
    },
    {
      label: "手机号码",
      prop: "phone",
      display: true,
    },
    {
      label: "创建时间",
      prop: "createTime",
      display: true,
      formatter: (row) => {
        return dateFormat(row.createTime)
      }
    },
  ],
}

export const initFormData = () => {
  return {
    password: undefined,
    wpassword: undefined
  }
}
